<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js" type="text/javascript"></script>
  <style>

  </style>
</head>

<body>
  <div id='root'>
    <ac></ac>
    <bc></bc>
  </div>

  <script>
    let cComponent = {
      data() {
        return {
          c: 'ccccc',
          count: 0
        }
      },
      methods: {
        hello() {
          console.log('hello from mixin!')
        },
        add() {
          this.count++;
        }
      }
    }

    // * 局部注册组件
    let aComponent = {
      data: function () {
        return {
          msg: 'aaaaa',
          c: 'aaaaaaa'
        }
      },
      mixins: [cComponent],
      template: `
                <div>
                    <div>a组件 {{ c }}</div>
                    <div>{{count}} <button @click='add'>add</button></div>
                    <button @click='hello'>a</button>
                </div>
            `,
      methods: {
        test() {
          console.log(1);
        },
        hello() {
          console.log('hello from a component!')
        }
      }
    }

    let bComponent = {
      data: function () {
        return {
          text: ''
        }
      },
      mixins: [cComponent],
      template: `
                <div>
                    <div>b组件</div>
                    <button @click='hello'>hello</button>
                </div>
            `,
      methods: {
        test() {
          console.log(1);
        }
      },
    }



    let vm = new Vue({
      el: '#root',
      // * 局部注册组件
      components: {
        ac: aComponent,
        bc: bComponent
      },
      data: function () {
        return {

        }
      },
      methods: {

      },
      computed: {

      }
    })

  </script>
</body>

</html>
